package com.tanhua.server.controller;

import com.tanhua.domain.vo.UserInfoVo;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 我的 功能模块
 */
@RestController
@RequestMapping("/users")
public class UserInfoController {

    @Autowired
    private UserService userService;

    /**
     * 查看用户登录信息
     * @param userID
     * @param huanxinID
     * @return
     */
    @GetMapping
    public ResponseEntity getUserInfo(Long userID, Long huanxinID){

        //TODO
        //userId与huanxinId 暂时不先处理，等即时通讯时再来处理

        UserInfoVo vo =  userService.getLoginUserInfo();
        return ResponseEntity.ok(vo);
    }

    /**
     * 更新用户基本信息
     * @param VO
     * @return
     */
    @PutMapping
    public ResponseEntity updateUserInfo( @RequestBody UserInfoVo VO){
        //调用业务
        userService.updateUserInfo(VO);
        return ResponseEntity.ok(null);
    }

    /**
     * 更新用户头像
     * @param headPhoto
     * @return
     */
    @PostMapping("/header")
    public ResponseEntity updateAvatar( MultipartFile headPhoto){

        //调用业务
        userService.updateAvatar(headPhoto);
        return ResponseEntity.ok(null);
    }
}
